<template>
  <div class="container">
    <div class="head">
      <div class="img">
        <img src="../../assets/NJUST.jpeg" />
      </div>
      <div class="person">
        <img src="../../assets/用户名.png" />
  <li class="li1"><router-link to="/person"><span>个人主页</span></router-link></li>
  </div>
  <div class="list">
    <img src="../../assets/购物车.png" />
  <li class="li1"><router-link to="/sample"><span>我的清单</span></router-link></li>
  </div>
  </div>

  <div class="crumbs">
    <nav>
      <router-link to="/home1"><span>首页</span><span>/</span></router-link>
      <router-link to="/home1"><span>{{ staName }}</span><span>/</span></router-link>
      <router-link :to="{
        name: 'Home2', 
        params: {
          param: this.staId,
          param1: this.staName
        }
      }"><span>{{ pjName }}</span></router-link>
    </nav>
  </div>

  <div class="background-image">
    <div class="content">
      <main class="main-content">
        <h1>请选择您要处理的模块</h1>
        <div class="module-grid">
          <button @click="handleModuleClick('人员')">人员</button>
          <button @click="handleModuleClick('设备')">设备</button>
          <button @click="handleModuleClick('规程')">规程</button>
        </div>
        <div class="footer-content">
          <div class="back">
            <img src="../../assets/返回.png" @click="goBack" />
          </div>
        </div>
      </main>
    </div>
  </div>

  <div v-if="isModalVisible" class="modal" @click.self="closeModal">
    <div class="modal-content" @click.stop>
      <div class="modal-header">
        <h3>选择模块</h3>
        <span class="close-btn" @click="closeModal">&times;</span>
      </div>
      <div class="modal-body">
        <div class="modal-grid">
          <button class="modal-button" @click="selectModule('培训')">
            <span class="button-icon">📚</span>
            <span class="button-text">培训</span>
          </button>
          <button class="modal-button" @click="selectModule('考核')">
            <span class="button-icon">📝</span>
            <span class="button-text">考核</span>
          </button>
        </div>
      </div>
    </div>
  </div>

  <!-- 提示框 -->
  <!-- 提示框 -->
  <div v-if="isAlertVisible" class="alert">
    <p>您的学习进度未达到要求!</p>
    <button @click="closeAlert">继续学习</button>
  </div>

  <!-- 遮罩层 -->
  <div v-if="isAlertVisible" class="mask"></div>

  </div>
</template>

<script>
export default {
  name: 'ModuleSelection',
  data() {
    return {
      id: '',
      staName: '',
      pjName: '',
	staId:'',
      isModalVisible: false,
      learningProgress: 85, // 假设的学习进度，实际应用中应从后端获
      isAlertVisible: false, // 控制提示框显示的属性
      alertMessage: '', // 提示框消息
      isAlertVisible: false, // 控制提示框和遮罩层显示的属性
    };
  },
  created() {
    this.pjName =  this.$route.params.pjName;
    this.staName = this.$route.params.staName;
    this.id = this.$route.params.pjId;
    this.staId=this.$route.params.staId;
  },
  methods: {
    handleModuleClick(module) {
      if (module === '人员') {
        this.isModalVisible = true;
      } else if (module === '设备') {
         this.$router.push({name:"device",params:{staName:this.staName,pjName:this.pjName,pjId:this.id,staId:this.staId}});
      } else if (module === '规程') {
        this.$router.push({name:"regulation",params:{staName:this.staName,pjName:this.pjName,pjId:this.id,staId:this.staId}});
      } else {
        console.log(`Selected module: ${module}`);
      }
    },
    openModal() {
      this.isModalVisible = true;
    },
    closeModal() {
      this.isModalVisible = false;
    },
    selectModule(module) {
      if (module === '培训') {
       this.$router.push({name:"Training",params:{staName:this.staName,pjName:this.pjName,pjId:this.id,staId:this.staId}});
      } else if (module === '考核') {
        this.$http.get(`/findStudyByPjId/${this.id}`).then((response) => {
            this.study=response.data;
            this.learningProgress = this.study.sStatus;
            if (this.learningProgress < 90 ||Object.keys(response.data).length === 0) {
              this.isAlertVisible = true;
              this.alertMessage = '您的学习进度不足90%，无法进入考核界面，请继续学习。';
            } else {
                this.$router.push({name:"Assessment",params:{staName:this.staName,pjName:this.pjName,pjId:this.id,staId:this.staId,sId:this.study.sId}});
            }
        });
        
      }
      this.closeModal(); // 关闭模态框
    },
    goBack() {
      this.$router.push({ path: '/home1' });
    },
    closeAlert() {
      this.isAlertVisible = false;
    }
  }
}
</script>

<style scoped>
  .container {
    width: 100%;
    /*  max-width: 1200px;*/
    margin: 0 auto;
    font-family: Arial, sans-serif;
  }

  .head {
    width: 100%;
    background-color: #abe0f3;
    height: 6vh;
  }

    .head .img {
      height: 100%;
      float: left;
    }

      .head .img img {
        height: 100%;
      }

    .head .list {
      float: right;
      height: 45%;
    }

      .head .list img {
        margin-top: 15px;
        margin-right: 7px;
        height: 100%;
        float: left;
      }

      .head .list li {
        margin-top: 20px;
        margin-right: 40px;
        display: block;
        float: left;
        font-size: 18px;
      }

    .head .person {
      float: right;
      height: 42%;
    }

      .head .person img {
        margin-top: 15px;
        margin-right: 7px;
        height: 100%;
        float: left;
      }

      .head .person li {
        margin-top: 20px;
        margin-right: 70px;
        display: block;
        float: left;
        font-size: 18px;
      }

  .crumbs {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    background-color: #f0f0f0;
    margin-bottom: 20px;
  }

    .crumbs nav {
      display: flex;
      align-items: center;
      gap: 8px;
    }

      .crumbs nav a {
        text-decoration: none;
        color: #333;
        font-size: 14px;
      }

      .crumbs nav span {
        color: #333;
      }

      .crumbs nav a:hover span {
        color: #409EFF;
      }

  .background-image {
    float: left;
    width: 100vw;
    height: 80vh;
    margin-top: 20vh;
    display: flex;
    justify-content: center;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    background-color: #fff;
    z-index: 0;
  }

    .background-image::before {
      content: "";
      position: absolute;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background: url("../../assets/Home-bg.jpg") center/cover no-repeat;
      z-index: -1;
      filter: blur(8px);
    }

  .content {
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 95%;
    width: 1200px;
    border-radius: 10px;
    background-color: #FFFFFF;
    position: relative; /* Added to position the nav absolutely */
  }

  .main-content {
    margin-top: 10vh;
    text-align: center;
  }

  .module-grid {
    display: flex;
    justify-content: space-around;
    margin-top: 20px;
    font-size: 50px;
  }

    .module-grid button {
      margin-top: 12vh;
      width: 200px;
      height: 150px;
      margin-right: 20px;
      border-radius: 8px;  /* 增加圆角 */
      background: linear-gradient(145deg, #20B2AA, #48D1CC);  /* 渐变背景 */
      color: white;
      font-size: 26px;
      padding: 10px 20px;
      cursor: pointer;
      border: none;
      box-shadow: 0 4px 15px rgba(0, 0, 0, 0.1);  /* 添加阴影 */
      transition: all 0.3s ease;  /* 平滑过渡效果 */
    }

      /* 添加悬停效果 */
      .module-grid button:hover {
        transform: translateY(-5px);  /* 悬浮上移效果 */
        box-shadow: 0 6px 20px rgba(0, 0, 0, 0.15);  /* 悬浮时加深阴影 */
        background: linear-gradient(145deg, #48D1CC, #20B2AA);  /* 悬浮时反转渐变 */
      }

  .footer-content {
    display: flex; /* 使用Flexbox布局 */
    justify-content: flex-end; /* 水平方向对齐到容器的末尾 */
    align-items: flex-end; /* 垂直方向对齐到容器的末尾 */
    position: relative; /* 相对定位 */
    bottom: 0; /* 底部对齐 */
    right: 0; /* 右侧对齐 */
    width: 100%; /* 宽度占满整个容器 */
    z-index: 10; /* 确保图片在其他内容之上 */
  }

  /*.footer-image {
  max-width: 20px;*/ /* 根据需要调整大小 */
  /*max-height: 20px;*/ /* 根据需要调整大小 */
  /*}*/

  .back {
    float: right;
    margin-top: 70px;
    margin-right: -100px;
  }

    .back img {
      height: 60px;
      cursor: pointer; /* 当鼠标悬停时显示为手型 */
      transition: all 0.3s ease;
      filter: drop-shadow(0 4px 6px rgba(0,0,0,0.1));
    }

    .back img:hover {
      transform: scale(1.1) rotate(-5deg);
      filter: drop-shadow(0 6px 8px rgba(0,0,0,0.15));
    }

  .modal {
    display: flex;
    justify-content: center;
    align-items: center;
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    z-index: 1000;
    backdrop-filter: blur(8px);
  }

  .modal-content {
    background: white;
    border-radius: 20px;
    width: 600px;
    box-shadow: 0 15px 50px rgba(0,0,0,0.3);
    border: 1px solid rgba(255,255,255,0.1);
    overflow: hidden;
    transform: scale(0.95);
    animation: modal-pop 0.3s ease-out forwards;
  }

  .modal-header {
    padding: 25px 30px;
    background: linear-gradient(135deg, #20B2AA, #48D1CC);
    color: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid rgba(255,255,255,0.1);
  }

  .modal-header h3 {
    margin: 0;
    font-size: 24px;
    font-weight: 600;
    letter-spacing: 0.5px;
  }

  .close-btn {
    font-size: 32px;
    color: white;
    cursor: pointer;
    transition: all 0.3s ease;
    opacity: 0.8;
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
  }

  .close-btn:hover {
    transform: rotate(90deg);
    opacity: 1;
    background: rgba(255,255,255,0.1);
  }

  .modal-body {
    padding: 40px;
    background: linear-gradient(135deg, #f8f9fa, #ffffff);
  }

  .modal-grid {
    display: flex;
    justify-content: center;
    gap: 40px;
    margin-top: 10px;
  }

  .modal-button {
    width: 180px;
    height: 180px;
    border: none;
    border-radius: 16px;
    background: white;
    box-shadow: 0 8px 20px rgba(0,0,0,0.1);
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 25px;
    position: relative;
    overflow: hidden;
  }

  .modal-button::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 4px;
    background: linear-gradient(90deg, #20B2AA, #48D1CC);
    transform: translateY(-100%);
    transition: transform 0.3s ease;
  }

  .modal-button:hover {
    transform: translateY(-5px);
    box-shadow: 0 12px 25px rgba(0,0,0,0.15);
  }

  .modal-button:hover::before {
    transform: translateY(0);
  }

  .button-icon {
    font-size: 42px;
    margin-bottom: 15px;
    transition: transform 0.3s ease;
  }

  .modal-button:hover .button-icon {
    transform: scale(1.1);
  }

  .button-text {
    font-size: 20px;
    font-weight: 600;
    color: #2c3e50;
    transition: color 0.3s ease;
  }

  .modal-button:hover .button-text {
    color: #20B2AA;
  }

  @keyframes modal-pop {
    0% {
      opacity: 0;
      transform: scale(0.9) translateY(-20px);
    }
    100% {
      opacity: 1;
      transform: scale(1) translateY(0);
    }
  }

  /* 提示框 */
  /* 提示框 */
  .alert {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: white;
    border-radius: 12px;
    padding: 25px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    z-index: 1000; /* 确保提示框在最上层 */
    text-align: center;
  }

    .alert button {
      display: inline-block;
      padding: 10px 25px;
      font-size: 16px;
      font-weight: 500;
      color: #fff;
      background-color: #f56c6c;
      border: none;
      border-radius: 4px;
      cursor: pointer;
      transition: all 0.3s ease;
    }

      .alert button:hover {
        background-color: #e45959;
        transform: translateY(-2px);
      }

  /* 遮罩层 */
  .mask {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: rgba(0, 0, 0, 0.5);
    z-index: 999; /* 遮罩层在提示框下一层 */
  }
</style>
